﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ForumLibrary.Data
{
    public class ForumWebManager : ForumManager
    {
                
        public ForumWebManager()
        {
            
        }

        public override object searchForNewFriend(string username, string searchedUser)
        {
            return _db.searchForNewFriend(username, searchedUser);
        }

        public override object getUser(string username)
        {
            if (username == null)
                return null;
            User u = _db.getUser(username);
            updateLogginState(new List<User>(new User[]{u}));
            return u;
        }

        public override object  getUsers()
        {
            List<User> db_users = _db.getUsers();
            updateLogginState(db_users);
            return db_users;
        }

        public override object  getFriends(string username)
        {
            List<User> db_friends = _db.getFriends(username);
            updateLogginState(db_friends);
            return db_friends;
        }

        private void updateLogginState(List<User> users)
        {
            foreach (User u in users)
            {
                ForumUser client = _users.Find(user => user.Username.Equals(u.Username)); //We aren't rely on the LoggedIn state inside the DB. Chezi
                if(client != null)
                    u.LoggedIn = client.LoginState;
            }
        }

        public override object  getForums()
        {
            return _db.getForums();
        }

        public object getForumsData()
        {
            return _db.getForumsData();
        }

        public override object  getThreads(string forumName)
        {
            return _db.getThreads(forumName);
        }

        public override object  getPosts(string forumName, string threadName)
        {
            return _db.getPosts(forumName, threadName);
        }

        //------------------------Methods only for ForumGUIManager-------------------------//
        public override bool isPostOwnerOrModerator(string forumName, string threadName, string PostName, string username)
        {
            throw new NotImplementedException();
        }

        public override string getThreadDetails(string _forum, string header)
        {
            throw new NotImplementedException();
        }

        public override string getPostDetails(string forum, string thread, string header)
        {
            throw new NotImplementedException();
        }
    }
}
